<?php

if(!defined('_HTML_SEARCH_')) {
define('_HTML_SEARCH_', 1);

function itstock_html_search_init($type){
  itstock_structure($data, $type);
  $data['page_idx'] = isset($_GET['idx'])?intval($_GET['idx']):0;
  $data['offset'] = $data['page_idx']*_ITSTOCK_MAX_ROWS_;
  if (isset($_GET['id'])) {
      $data['where'][0] = sprintf("`%s`.`id`='%s'", $data['table'], itstock_decode($_GET['id']));
  } else {
    if(isset($_GET['search'])){
      $data['search'] = itstock_db_escape($_GET['search']);
    }
  }
  return $data;
}

function itstock_html_search($page, $ajax = false, $post = false){
?>
  <label>Search:</label>&nbsp;
  <input type="text" id="search<?php echo ($ajax?'_ajax':'');?>" onkeyup="(event.keyCode === 13 )? itstock_search(<?php echo "'$page'"; echo ($ajax?', this':'');?>) : false;" value="<?php
    echo (isset($_GET['search']) ? $_GET['search']:'');
  ?>" size="20">
  <img src="img/search.png" title="Search" onclick="itstock_search(<?php echo "'$page'"; echo ($ajax?', this':'');?>);">
<?php
}

}
?>
